
class_name CSevenDayTask

extends EventDispatcher

signal UUID_changed(old_value, new_value) 
signal Deadline_changed(old_value, new_value) 
signal OpenedDay_changed(old_value, new_value) 
signal Progress_changed(old_value, new_value) 
signal HasGetProgress_changed(old_value, new_value) 


var m_tblAlias
var bInited = false
func _init(_uuid)->void:
    self.UUID = _uuid
    self.Deadline = 0	# 活动结束时间
    self.OpenedDay = 0	# 已开放的天数 用于更新任务
    self.Progress = 0	# 活动进度值 完成任务增加
    self.HasGetProgress = 0	# 已领取最大进度奖励

    self.m_tblAlias = {
 
    }

func UnPack(_bufferStream):
    self.UUID = _bufferStream.ReadInt64()
    self.Deadline = _bufferStream.ReadUint32()
    self.OpenedDay = _bufferStream.ReadUint32()
    self.Progress = _bufferStream.ReadUint32()
    self.HasGetProgress = _bufferStream.ReadUint8()

    self.bInited = true


func GetTableName():
    return 'SevenDayTask'

func CopyFrom(other):
    self.Deadline = other.Deadline
    self.OpenedDay = other.OpenedDay
    self.Progress = other.Progress
    self.HasGetProgress = other.HasGetProgress


func OnDataChanged( fieldName, oldValue, newValue):
    if oldValue == newValue:
        return
    
    self.DispatchEvent(fieldName, [self, oldValue, newValue])
    #  Alias
    if self.m_tblAlias[fieldName] != null:
        for i in range(self.m_tblAlias[fieldName].size()):
            self.DispatchEvent(self.m_tblAlias[fieldName][i], [self, oldValue, newValue])

func UnPackField(_fieldId, _bufferStream, _varLen ):
    if _fieldId < 0 or _fieldId == 0xffff:
        var old = CSevenDayTask.new(self.m_UUID)
        old.CopyFrom( self )
        self.UnPack( _bufferStream )
        self.DispatchEvent("CSevenDayTask", [self, old, self])
        return true

    print("UnPackField error tblName = SevenDayTask, className = CSevenDayTask, _fieldId = ", _fieldId)
    # if _fieldId > Fields_SevenDayTaskID.size():
    #     var szLog = 'CSevenDayTask.UnPackField  _fieldId(%d) < 0 or _fieldId(%d) > #Fields_SevenDayTaskID(%d)' % [_fieldId, _fieldId,  Fields_SevenDayTaskID.size()]
    #     print(szLog)
    #     return false

    # Fields_SevenDayTaskID[_fieldId].reader( self, _bufferStream, _varLen)

    return true

func AddField(_fieldId, _bufferStream):
    print( "[TABLEDATA] error AddField", "CSevenDayTask", _fieldId )

    
func DelField(_fieldId ):
    print( "[TABLEDATA] error DelField", "CSevenDayTask", _fieldId )

var UUID:
    set(value):
        var old = self.m_UUID
        self.UUID = _value
        self.UUID_changed.emit(old, _value)

    get:
        return self.UUID


var Deadline:
    set(value):
        var old = self.m_Deadline
        self.Deadline = _value
        self.Deadline_changed.emit(old, _value)

    get:
        return self.Deadline


var OpenedDay:
    set(value):
        var old = self.m_OpenedDay
        self.OpenedDay = _value
        self.OpenedDay_changed.emit(old, _value)

    get:
        return self.OpenedDay


var Progress:
    set(value):
        var old = self.m_Progress
        self.Progress = _value
        self.Progress_changed.emit(old, _value)

    get:
        return self.Progress


var HasGetProgress:
    set(value):
        var old = self.m_HasGetProgress
        self.HasGetProgress = _value
        self.HasGetProgress_changed.emit(old, _value)

    get:
        return self.HasGetProgress



